package folderLogger.fileFilters;

import java.io.File;
import java.io.FileFilter;

public class ExtensionExcludeFilter implements FileFilter {

	private String[] notSupportedExtensions; 	
	private int extensionsCount;
		
	public ExtensionExcludeFilter(String[] notSupportedExtensions)
	{
		this.notSupportedExtensions = notSupportedExtensions;
		extensionsCount = notSupportedExtensions.length;
	}


	@Override
	public boolean accept(File currentFile) {
		String fileExtension = getExtension(currentFile);
		for(int i=0; i<extensionsCount; i++)
		{
			if(fileExtension.equalsIgnoreCase(notSupportedExtensions[i]))
			{
				return false;
			}
		}
		return true;
	}
	
	public String getExtension(File file)
	{
		String fileName = file.getName();
		int extensionIndex = fileName.lastIndexOf('.');
		return extensionIndex == -1 ? "" : fileName.substring(extensionIndex+1);
	}

}
